<% include common/header.ejs %>
<style>
    a.ftcolor{
        padding-top:32px;
        padding-left:32px;
    }
    a.ftcolor i{
        font-style: normal;
    }
    a.ftcolor strong{
        font-weight: normal;
        color:orange;
    }
</style>
<body>


        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6-12位数</div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a class="ftcolor" href="/reg">
                        <i>没有账号?<i/>
                            <strong>前去注册</strong>
                    </a>

                </div>
            </div>
        </form>



<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        var $ =layui.$;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //console.log(data)
            $.ajax({
                url:'/login',
                method:'post',
                data:{
                    username:data.field.username,
                    password:data.field.password
                },
                success:function(data){
                    layer.alert(data.msg, function(){
                        if(data.code === 200){
                            location.href='/'
                        }

                    });

                    // if(data.code === 200){
                    //     layer.alert(data.msg)
                    // }
                    // if(data.code === 300){
                    //     layer.alert(data.msg)
                    // }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>